﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Export2IMG
{
    public partial class Preview : Form
    {

        public Preview()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        public void SetText(string soCMND, string hoTen, string namSinh, string nguyenQuan,
           string noiDKHK, string noiDKHK_TS, string ngayCap,
           string thangCap, string namCap, string noiCap, string imageURL)
        {
            this.pnlCMND.SoCMND = soCMND;
            this.pnlCMND.HoTen = hoTen;
            this.pnlCMND.NamSinh = namSinh;
            this.pnlCMND.NguyenQuan = nguyenQuan;
            this.pnlCMND.NoiDKHK = noiDKHK;
            this.pnlCMND.NoiDKHK_TS = noiDKHK_TS;
            this.pnlCMND.NgayCap = ngayCap;
            this.pnlCMND.ThangCap = thangCap;
            this.pnlCMND.NamCap = namCap;
            this.pnlCMND.NoiCap = noiCap;
            this.pnlCMND.ImageURL = imageURL;
        }

        private void btnSaveImage_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
            saveFileDialog1.Title = "Save an Image File";
            saveFileDialog1.FileName = "images001";
            saveFileDialog1.ShowDialog();
        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            string fileName = saveFileDialog1.FileName;

            Bitmap image = new Bitmap(1219, 421);
            this.pnlCMND.DrawToBitmap(image, this.pnlCMND.ClientRectangle);
            image.Save(fileName);
            Console.WriteLine("Save success");
        }

        public void ExportImage(string fileName)
        {
            Bitmap image = new Bitmap(1219, 421);
            this.pnlCMND.DrawToBitmap(image, this.pnlCMND.ClientRectangle);
            image.Save(fileName);
            Console.WriteLine("Save success");
        }
    }
}
